import os
import pandas as pd

def create_v0(Path):
    path = Path
    train_txt_name = "../init_data/toUser/my_train_pair.txt"

    data = pd.read_csv("../init_data/toUser/annos.csv") # 标签文件，查看每一个每一个文件对应是否为同一人脸
    value = data.iloc[:, 1].tolist()

    k = 1 # k为人数
    with open(train_txt_name, 'w') as f:
        for i in os.listdir(path):
            if i.isdigit():
                if value[int(i)] == 1:
                    f.write("{}/a.jpg {}\n".format(i, k))
                    f.write("{}/b.jpg {}\n".format(i, k))
                else:
                    f.write("{}/a.jpg {}\n".format(i, k))
                    k += 1
                    f.write("{}/b.jpg {}\n".format(i, k))
            else:
                new_path = os.path.join(path,i)
                for j in os.listdir(new_path):
                    f.write("{}/{} {}\n".format(i,j,k))
            k += 1
    f.close()
    return k-1

def create_v1(Path): # 本次txt生成走v1版本
    path = Path
    train_txt_name = "../init_data/toUser/my_train_pair.txt"

    # TODO 这里k从0开始，那么trian得label = label-1是不是可以去除？
    k = 1 # k为人数
    with open(train_txt_name, 'w') as f:
        for i in os.listdir(path): # 同一文件下下路径标签都为一个K
            new_path = os.path.join(path,i)
            for j in os.listdir(new_path):
                f.write("{}/{} {}\n".format(i,j,k))
            k += 1
    f.close()
    return k-1 # 根据代码，因为K会多出一个，组合种类数要减去一个

def test_create(Path):
    path1 = Path
    test_txt_name = "../init_data/toUser/my_test_pair.txt"

    with open(test_txt_name,'w') as f:
        for i in os.listdir(path1):
            f.write("{}/a.jpg {}/b.jpg\n".format(i, i))
    f.close()
